|
|
|
|
|
|
|
'*****************************************************************
Close intFileNum
End Sub |
|
|
|
|
|
|
|
|
You might notice that the OpenFile routine simply loads the file into the text box on the active window by referencing the ActiveForm property. This is a valid assumption to make, because the active menu will always refer to the active form. Because the user can open a file via the menu (even if he or she is using the toolbar), you can always assume that any actions you perform in your menu event handlers should be applied to the active form. |
|
|
|
|
|
|
|
|
Now that you have had a chance to understand what your MDI parent form is responsible for, let's take a look at how the child should behave in this parent/child relationship. |
|
|
|
|
|
|
|
|
As mentioned earlier, child forms are responsible for calling the WindowCreated and WindowDestroyed methods of the MDI parent form. Listing 17.9 demonstrates how this is done from the Form_Load and Form_Unload events. In addition, your child window sets its initial caption based on the MDI parent ChildWindowCount property. Although this technique is good for this sample, you might want to make your algorithm for setting your initial caption a little more complex. What do you think would happen if you had three windows, closed the second window, and then created a new window? How could you avoid this problem? |
|
|
|
|
|
|
|
|
Listing 17.9 MDICHILD.TXTUse the Child Form for Code Specific to Each Child |
|
|
|
|
|
|
|
|
'*********************************************************************
' MDIChild.frm - Demonstrates some basic techniques on how a MDI child
' window should behave.
'*********************************************************************
Option Explicit
'*********************************************************************
' When a new form is created it should call the WindowCreated function
' in the MDI parent form (which increments the window count in this
' case). It should also set its caption to distinguish it from other
' child windows.
'*********************************************************************
Private Sub Form_Load()
MDIParent.WindowCreated
'*****************************************************************
' This works, but it has a fatal flaw.
'*****************************************************************
Caption = Caption & " - " & MDIParent.ChildWindowCount
End Sub
'*********************************************************************
' Make sure txtData always fills the client area of the form.
'********************************************************************* |
|
|
|
|
|